module CustomerServiceHelper

  #post方式请求elephant数据
  # service_path 服务器路径，把斜杠替换成逗点 eg city/current_city  city,current_city
  # params 参数
  def self.post_data(service_path,params)

    #发送推送
    url = "#{RestConfig::CUSTOMER_SERVER}/api/#{service_path.gsub(/,/, '/')}"
    params.delete("service_path")
    response = RestClient.post url, params
    JSON.parse(response.body)
  end


  #get方式请求elephant数据
  # service_path 服务器路径，把斜杠替换成逗点 eg city/current_city  city,current_city
  # params 参数
  def self.get_data(service_path,params)

    #发送推送
    url = "#{RestConfig::CUSTOMER_SERVER}/api/#{service_path.gsub(/,/, '/')}"
    params.delete("service_path")
    response = RestClient.get url, {:params => params}
    JSON.parse(response.body)
  end


  # put方式请求elephant数据
  # service_path 服务器路径，把斜杠替换成逗点 eg city/current_city  city,current_city
  # params 参数
  def self.put_data(service_path,params)

    url = "#{RestConfig::CUSTOMER_SERVER}/api/#{service_path.gsub(/,/, '/')}"
    params.delete("service_path")
    response = RestClient.put url, params
    JSON.parse(response.body)
  end



  # put方式请求elephant数据
  # service_path 服务器路径，把斜杠替换成逗点 eg city/current_city  city,current_city
  # params 参数
  def self.delete_data(service_path,params)

    #发送推送
    url = "#{RestConfig::CUSTOMER_SERVER}/api/#{service_path.gsub(/,/, '/')}"
    params.delete("service_path")
    response = RestClient.delete url, params
    JSON.parse(response.body)
  end


  #patch方式请求elephant数据
  # service_path 服务器路径，把斜杠替换成逗点 eg city/current_city  city,current_city
  # params 参数Hash对
  def self.patch_data(service_path,params)

    #发送推送
    url = "#{RestConfig::CUSTOMER_SERVER}/api/#{service_path.gsub(/,/, '/')}"
    params.delete("service_path")
    response = RestClient.patch url, params
    JSON.parse(response.body)
  end
end
